import i from "./NodePool"
import r from "./PropPrefabCtrl"
import n from "./MatchGameConfig"


const { ccclass, property } = cc._decorator;

@ccclass
class PropsCtrl {
    propItem = null;
    propParent = null;
    propMaskParent = null;
    isReady = false;

    static _instance = null;

    static getInstance(): PropsCtrl {
        if (!this._instance) {
            this._instance = new PropsCtrl();
        }
        return this._instance;
    }
    ready(e, t, a?) {
        this.propItem = e;
        this.propParent = t;
        this.propMaskParent = a || null;
        i.initPool(this.propItem, 0, n.SquarePool.PropItem);
        this.isReady = true;
    };
    init() { };
    createPropItem(e, t, a, o?) {
        void 0 === o && (o = false);
        var l = i.getNode(n.SquarePool.PropItem);
        l.parent = o ? this.propMaskParent : this.propParent;
        l.getComponent(r) || l.addComponent(r);
        var s = l.getComponent(r);
        s.init(e, t, a);
        return s;
    };
    destoryPropItem(e) {
        if (e.getComponent(r)) {
            e.getComponent(r).destorySelf();
            i.putNode(n.SquarePool.PropItem, e);
        }
    };
    destoryPropItems(e) {
        e.forEach( (e) => {
            if (e.getComponent(r)) {
                e.getComponent(r).destorySelf();
                i.putNode(n.SquarePool.PropItem, e);
            }
        });
    };
}
export default PropsCtrl.getInstance();